package com.binest.system.webMessage.controller;

import com.binest.common.annotation.Log;
import com.binest.common.core.controller.BaseController;
import com.binest.common.core.domain.AjaxResult;
import com.binest.common.core.page.TableDataInfo;
import com.binest.common.enums.BusinessType;
import com.binest.common.utils.poi.ExcelUtil;
import com.binest.system.webMessage.domain.WebMessage;
import com.binest.system.webMessage.service.IWebMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 网站消息Controller
 *
 * @author wwd
 * @date 2024-02-02
 */
@RestController
@RequestMapping("/webMessage")
public class WebMessageController extends BaseController
{
    @Autowired
    private IWebMessageService webMessageService;

    /**
     * 查询网站消息列表
     */
//    @PreAuthorize("@ss.hasPermi('webMessage:webMessage:list')")
    @GetMapping("/list")
    public TableDataInfo list(WebMessage webMessage)
    {
        startPage();
        List<WebMessage> list = webMessageService.selectWebMessageList(webMessage);
        return getDataTable(list);
    }

    /**
     * 导出网站消息列表
     */
//    @PreAuthorize("@ss.hasPermi('webMessage:webMessage:export')")
    @Log(title = "网站消息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WebMessage webMessage)
    {
        List<WebMessage> list = webMessageService.selectWebMessageList(webMessage);
        ExcelUtil<WebMessage> util = new ExcelUtil<WebMessage>(WebMessage.class);
        util.exportExcel(response, list, "网站消息数据");
    }

    /**
     * 获取网站消息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('webMessage:webMessage:query')")
    @GetMapping(value = "/getInfo")
    public AjaxResult getInfo(String id)
    {
        return success(webMessageService.selectWebMessageById(id));
    }

    /**
     * 新增网站消息
     */
//    @PreAuthorize("@ss.hasPermi('webMessage:webMessage:add')")
    @Log(title = "网站消息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WebMessage webMessage)
    {
        return toAjax(webMessageService.insertWebMessage(webMessage));
    }

    /**
     * 修改网站消息
     */
//    @PreAuthorize("@ss.hasPermi('webMessage:webMessage:edit')")
    @Log(title = "网站消息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody WebMessage webMessage)
    {
        return toAjax(webMessageService.updateWebMessage(webMessage));
    }

    /**
     * 删除网站消息
     */
//    @PreAuthorize("@ss.hasPermi('webMessage:webMessage:remove')")
    @Log(title = "网站消息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(webMessageService.deleteWebMessageByIds(ids));
    }
}
